<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/8/10 0010
 * Time: 上午 8:46
 */

namespace System\AdminBundle\Voter;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

class AdminVoter implements  VoterInterface {

    public function supportsAttribute($attribute)
    {
        return in_array($attribute,array('ROLE_PARENT_LEADER',"ROLE_TEACHER","ROLE_ADMIN","ROLE_SYSTEM_ADMIN"));
    }

    public function supportsClass($class)
    {
//        return array('Model\UserBundle\Entity\User');
        return false;
    }

    public function vote(TokenInterface $token, $object, array $attributes)
    {
        $userRole = $token->getRoles();
        foreach ($userRole as $roleObj) {
            var_dump($roleObj->getRole());
        }
        var_dump($object);
        var_dump($userRole);
        return VoterInterface::ACCESS_ABSTAIN;

    }
}